<?php
include_once ("../Login/databaseconnection.php");
$q=$_GET["q"];
$hint="";
$name=explode(" ",$q);
$fn=$name[0];
$ln=$name[1];
$resultt= mysql_query("SELECT * FROM teacher Where First_Name='$fn' AND Last_Name='$ln'");
if($row = mysql_fetch_array($resultt))
{
$Teacher_NIC=$row['T_NIC_Number'];
}
$hint=$hint.'<select name="Training_Name">';
   if(isset($_POST['SaveChanges']))
	  {
	  	 if(isset($_SESSION['Tra_Id']))
	   {
	  $Training_Id=$_SESSION['Tra_Id'];
	   unset($_SESSION['Tra_Id']);
	   }
	   	  }
	  if($Training_Id!="")
	  {
	  $resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Training_Name=$rownet['Training_Name'];
}
	 $hint=$hint.'<option value="'.$Training_Name.'">'.$Training_Name.'</option>';
	  }
	    else
	  {
	  $hint=$hint.'<option value="Select One">Select One</option>';
	  }
		   if($Teacher_NIC!="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM training_details WHERE Teacher_NIC='$Teacher_NIC'");
	  }
	  if($Teacher_NIC=="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM training_details");
	  }
  while($row=mysql_fetch_array($exa))
  {
	 $Tra_Id=$row['Training_Id'];
	 $result=mysql_query("SELECT * FROM training WHERE Training_Id='$Tra_Id'");
  if($row=mysql_fetch_array($result))
  {
		$Tra_Name=$row['Training_Name'];
}
if($Tra_Name!=$Training_Name)
{
	 $hint=$hint.'<option value="'.$Tra_Name.'">'.$Tra_Name.'</option>';
  }
  }
       $hint=$hint.'</select>';
  if($hint=="")
{
$response=$response.'<select name="Training_Id">';
   $response=$response.'<option value="Select One">Select One</option>';
	 $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM training_details");
   while($row=mysql_fetch_array($exa))
  {
	 $Tra_Id=$row['Training_Id'];
	 $result=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
  if($row=mysql_fetch_array($result))
  {
		$Tra_Name=$row['Training_Name'];
}
	$response=$response.'<option value="'.$Tra_Name.'">'.$Tra_Name.'</option>';
  }
$response=$response.'</select>';
}
else
{
$response=$hint;
}
echo $response;
?>